home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Sources / TextPart.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  19.5 KB  |  758 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                            TextPart.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                        Anthone Burbidge
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef _TEXTPART_
  14. #include "TextPart.h"
  15. #endif
  16.  
  17. #ifndef _TEXTFRAME_
  18. #include "TextFrame.h"
  19. #endif
  20.  
  21. #ifndef _RULERFRAME_
  22. #include "RulerFrame.h"
  23. #endif
  24.  
  25. #ifndef _TEXTUTIL_
  26. #include "TextUtil.h"
  27. #endif
  28.  
  29. #ifndef _STYLEINFO_
  30. #include "StyleInfo.h"
  31. #endif
  32.  
  33. #ifndef _TEXTPROXY_
  34. #include "TextProxy.h"
  35. #endif
  36.  
  37. #ifndef _VALUESTREAM_
  38. #include "ValueStream.h"
  39. #endif
  40.  
  41. #ifndef _TEXTSELC_
  42. #include "TextSelc.h"
  43. #endif
  44.  
  45. #ifndef _ODTEXT_
  46. #include "ODText.h"
  47. #endif
  48.  
  49. #ifndef _EMBEDRUN_
  50. #include "EmbedRun.h"
  51. #endif
  52.  
  53. // ----- Textension Includes -----
  54.  
  55. #ifndef _Textension_
  56. #include "Textension.h"
  57. #endif
  58.  
  59. #ifndef _TSMTextension_
  60. #include "TSMTextension.h"
  61. #endif
  62.  
  63. #ifndef _TextensionIOSuite_
  64. #include "TextensionIOSuite.h"
  65. #endif
  66.  
  67. #ifndef _QDTextRun_
  68. #include "QDTextRun.h"
  69. #endif
  70.  
  71. #ifndef _RulerObject_
  72. #include "RulerObject.h"
  73. #endif
  74.  
  75. // ----- Framework Includes -----
  76.  
  77. #ifndef FWUTIL_H
  78. #include "FWUtil.h"
  79. #endif
  80.  
  81. #ifndef FWPROXY_H
  82. #include "FWProxy.h"
  83. #endif
  84.  
  85. #ifndef FWRECT_H
  86. #include "FWRect.h"
  87. #endif
  88.  
  89. // ----- OpenDoc Includes -----
  90.  
  91. #ifndef _CMDDEFS_
  92. #include <CmdDefs.h>
  93. #endif
  94.  
  95. #ifndef _STDPROPS_
  96. #include <StdProps.h>
  97. #endif
  98.  
  99. #ifndef _MENUBAR_
  100. #include <MenuBar.h>
  101. #endif
  102.  
  103. #ifndef _SHAPE_
  104. #include <Shape.h>
  105. #endif
  106.  
  107. #ifndef _DRAFT_
  108. #include <Draft.h>
  109. #endif
  110.  
  111. #ifndef _WINDOW_
  112. #include <Window.h>
  113. #endif
  114.  
  115. #ifndef _XMPSESSM_
  116. #include <XMPSessM.h>
  117. #endif
  118.  
  119. #ifndef _DISPTCH_
  120. #include <Disptch.h>
  121. #endif
  122.  
  123. #ifndef _SUCURSOR_
  124. #include <SUCursor.h>
  125. #endif
  126.  
  127. #ifndef _INFO_
  128. #include <Info.h>
  129. #endif
  130.  
  131. #ifndef _STDTYPES_
  132. #include <StdTypes.h>
  133. #endif
  134.  
  135. #ifndef _TRANSLAM_
  136. #include <TranslaM.h>
  137. #endif
  138.  
  139. // ----- Macintosh Includes -----
  140.  
  141. #ifndef __FIXMATH__
  142. #include <FixMath.h>
  143. #endif
  144.  
  145. #ifndef __PACKAGES__
  146. #include <Packages.h>
  147. #endif
  148.  
  149. #ifndef __FONTS__
  150. #include <Fonts.h>
  151. #endif
  152.  
  153. #ifndef __SCRIPT__
  154. #include <Script.h>
  155. #endif
  156.  
  157. #ifndef mathRoutinesIncludes
  158. #include <Math Routines.h>
  159. #endif
  160.  
  161. // ----- TextPart Includes -----
  162.  
  163. #pragma segment TextPartSegment
  164.  
  165.  
  166. //========================================================================================
  167. // CLASS CTextPart
  168. //========================================================================================
  169.  
  170. const XMPPropertyName CTextPart::kTextPropertyName = "TextProperty";
  171. const XMPValueType    CTextPart::kTextensionTextType = "TextensionTextType";
  172.  
  173. CTextPart* CTextPart::gCurrentPart;
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // CTextPart::CTextPart
  177. //----------------------------------------------------------------------------------------
  178.  
  179. CTextPart::CTextPart() :
  180.     fFontMenu(NULL),
  181.     fSizeMenu(NULL),
  182.     fEmbedMenu(NULL),
  183.     fEditText(NULL),
  184.     fIsDrawing(false)
  185. {
  186. }
  187.  
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // CTextPart::~CTextPart
  191. //----------------------------------------------------------------------------------------
  192.  
  193. CTextPart::~CTextPart()
  194. {
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. // CTextPart::Initialize
  199. //----------------------------------------------------------------------------------------
  200.  
  201. void CTextPart::Initialize()
  202. {
  203.     FW_CEmbeddingPart::Initialize();
  204.     
  205.     fFontMenu = ::NewMenu(kFontMenu,"\pFont");
  206.     fSizeMenu = ::NewMenu(kSizeMenu,"\pSize");
  207.     fEmbedMenu = ::NewMenu(kEmbedMenu,"\pEmbed");
  208.  
  209.     if (!fFontMenu || !fSizeMenu)
  210.         ::DebugStr("\pError creating menus");
  211.     
  212.     ::AddResMenu(fFontMenu,'FOND');
  213.     
  214.     for (int i = 0; gFontSizeTable[i].fFontSize; i++)
  215.         ::AppendMenu(fSizeMenu, gFontSizeTable[i].fFontSizeName);
  216.  
  217.     ::AppendMenu(fEmbedMenu,"\pText");
  218.     ::AppendMenu(fEmbedMenu,"\pDraw");
  219.     ::AppendMenu(fEmbedMenu,"\pClock");
  220.     ::AppendMenu(fEmbedMenu,"\pMovie");
  221.  
  222.     XMPMenuBar *menuBar = GetMenuBar();
  223.     
  224.     menuBar->AddMenuLast(kFontMenu, fFontMenu, this);
  225.     menuBar->AddMenuLast(kSizeMenu, fSizeMenu, this);
  226.     menuBar->AddMenuLast(kSizeMenu, fEmbedMenu, this);
  227.     
  228.     // ----- Tokenize -----
  229.     fRulerPresentation = GetSession()->Tokenize(CTextPart_kRulerPresentation);
  230.     fMainPresentation = GetSession()->Tokenize(CTextPart_kMainPresentation);
  231.     fScrollerPresentation = GetSession()->Tokenize(CTextPart_kScrollerPresentation);
  232.  
  233.     CreateEditText();
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. // CTextPart::InternalizeContent
  238. //----------------------------------------------------------------------------------------
  239.  
  240. void CTextPart::InternalizeContent(XMPStorageUnit* storageUnit)
  241. {
  242.     storageUnit->Focus(kXMPPropContents, kXMPPosUndefined,
  243.                        this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
  244.  
  245.     CValueStream *stream = new CValueStream;
  246.     stream->InitValueStream(storageUnit);
  247.     
  248.     CTextensionIOSuite *ioSuite = new CTextensionIOSuite;
  249.     ioSuite->ITextensionIOSuite(false, stream);
  250.     
  251.     gCurrentPart = this;
  252.     
  253.     TReplaceParams replaceParams(ioSuite);
  254.     OSErr err = fEditText->ReplaceRange(0/*start*/, 0/*end*/, &replaceParams, true/*invisible*/);
  255.     
  256.     gCurrentPart = NULL;
  257.     
  258.     TOffsetRange selRange((long) 0, (long) 0);
  259.     if (!err)
  260.         fEditText->SetSelectionRange(selRange);
  261.     
  262.     ioSuite->Free();
  263.     delete ioSuite;
  264.     
  265.     stream->Free();
  266.     delete stream;
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. // CTextPart::ExternalizeContent
  271. //----------------------------------------------------------------------------------------
  272.  
  273. void  CTextPart::ExternalizeContent(XMPStorageUnit* storageUnit)
  274. {
  275.     storageUnit->Focus(kXMPPropContents, kXMPPosUndefined,
  276.                        this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
  277.  
  278.     CValueStream *stream = new CValueStream;
  279.     stream->InitValueStream(storageUnit);
  280.     
  281.     CTextensionIOSuite *ioSuite = new CTextensionIOSuite;
  282.     ioSuite->ITextensionIOSuite(false, stream);
  283.     
  284.     gCurrentPart = this;
  285.     
  286.     TOffsetRange range2Save(0, fEditText->CountChars());
  287.     OSErr err = fEditText->GetRangeIOSuite(&range2Save, ioSuite);
  288.     
  289.     gCurrentPart = NULL;
  290.     
  291. //    if (err)
  292. //        ErrorAlert(err);
  293.     
  294.     ioSuite->Free();
  295.     delete ioSuite;
  296.     
  297.     stream->Free();
  298.     delete stream;
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. // CTextPart::Draw
  303. //----------------------------------------------------------------------------------------
  304.  
  305. void CTextPart::Draw(XMPFacet* xmpFacet, XMPShape* invalidShape)
  306. {
  307.     fIsDrawing = true;
  308.     FW_CEmbeddingPart::Draw(xmpFacet, invalidShape);
  309.     fIsDrawing = false;
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. // CTextPart::NewFrame
  314. //----------------------------------------------------------------------------------------
  315.  
  316. FW_CFrame* CTextPart::NewFrame(XMPFrame* xmpFrame, XMPTypeToken presentation)
  317. {
  318.     FW_CFrame* frame = NULL;
  319.     
  320.     if (presentation == fRulerPresentation)
  321.     {
  322.         frame = new CRulerFrame();
  323.         ((CRulerFrame *) frame)->IRulerFrame(xmpFrame, this);
  324.     }
  325.     else
  326.     {
  327.         frame = new CTextFrame();
  328.         ((CTextFrame *) frame)->ITextFrame(xmpFrame, this);
  329.     }
  330.     
  331.     return frame;
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. // CDrawPart::NewSelection
  336. //----------------------------------------------------------------------------------------
  337.  
  338. FW_CSelection* CTextPart::NewSelection()
  339. {    
  340.     CTextSelection* selection = new CTextSelection;
  341.     selection->InitTextSelection(this);
  342.     return selection;
  343. }
  344.  
  345. //----------------------------------------------------------------------------------------
  346. // CTextPart::DoAdjustMenus
  347. //----------------------------------------------------------------------------------------
  348.  
  349. void CTextPart::DoAdjustMenus(XMPMenuBar* menuBar)
  350. {
  351.     FW_CEmbeddingPart::DoAdjustMenus(menuBar);
  352.  
  353.     short nItems, i;
  354.     Str255 fontName, itemName;
  355.     short fontSize;
  356.         
  357.     // ----- Check mark the font of the current selection.
  358.     
  359.     Boolean haveFontName = GetFont(fontName);
  360.     
  361.     nItems = ::CountMItems(fFontMenu);
  362.     for (i = 1; i <= nItems; i++)
  363.     {
  364.         ::GetItem(fFontMenu, i, itemName);
  365.         if (haveFontName && IUEqualString(itemName, fontName) == 0)
  366.             ::CheckItem(fFontMenu, i, true);
  367.         else
  368.             ::CheckItem(fFontMenu, i, false);
  369.     }
  370.         
  371.     // ----- Check mark the font size of the current selection.
  372.     
  373.     Str255 fontSizeName;
  374.     Boolean haveFontSize = GetFontSize(fontSize);
  375.     if (haveFontSize)
  376.         ::NumToString(fontSize, fontSizeName);
  377.     
  378.     nItems = ::CountMItems(fSizeMenu);
  379.     for (i = 1; i <= nItems; i++)
  380.     {
  381.         ::GetItem(fSizeMenu, i, itemName);
  382.         if (haveFontSize && IUEqualString(itemName, fontSizeName) == 0)
  383.             ::CheckItem(fSizeMenu, i, true);
  384.         else
  385.             ::CheckItem(fSizeMenu, i, false);
  386.     }
  387.     
  388.     // ----- Edit Menu -----
  389.     XMPTranslation *translate = GetSession()->GetTranslation();
  390.     XMPType kTEXTType = translate->GetISOTypeFromPlatformType('TEXT', kXMPPlatformDataType);
  391.     menuBar->EnableCommand(kXMPCommandSelectAll, fEditText->CountChars() > 0);
  392.     menuBar->EnableCommand(kXMPCommandPaste,
  393.                                 HasPropertyOnClipboard(kXMPPropContents, kSampleTextensionKind) ||
  394.                                 HasPropertyOnClipboard(kXMPPropContents, kTEXTType));
  395. }
  396.  
  397. //------------------------------------------------------------------------------
  398. // CTextPart::DoMenuEvent
  399. //------------------------------------------------------------------------------
  400.  
  401. FW_Boolean CTextPart::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
  402. {
  403.     if (menuBar->IsCommandSynthetic(commandID))
  404.     {
  405.         XMPMenuID menu;
  406.         XMPMenuItemID menuItem;
  407.         menuBar->GetMenuAndItem(commandID, menu, menuItem);
  408.         if (menu == kEmbedMenu)
  409.         {
  410.             HandleEmbedMenuEvent(menuItem);
  411.             return TRUE;
  412.         }
  413.     }
  414.     
  415.     return FW_CEmbeddingPart::DoMenuEvent(menuBar, commandID);
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. // CTextPart::GetContentPropertyValueType
  420. //----------------------------------------------------------------------------------------
  421.  
  422. XMPValueType CTextPart::GetContentPropertyValueType() const
  423. {
  424.     return kSampleTextensionKind;
  425. }
  426.  
  427. //----------------------------------------------------------------------------------------
  428. // CTextPart::NewProxyPart
  429. //----------------------------------------------------------------------------------------
  430.  
  431. FW_CProxyRun* CTextPart::NewProxyRun()
  432. {
  433.     CTextProxyRun *proxyRun = new CTextProxyRun();
  434.     proxyRun->InitTextProxyRun(this);
  435.     return proxyRun;
  436. }
  437.  
  438. //----------------------------------------------------------------------------------------
  439. // CTextPart::GetDefaultPresentation
  440. //----------------------------------------------------------------------------------------
  441.  
  442. XMPTypeToken CTextPart::GetDefaultPresentation() const
  443. {
  444.     return fMainPresentation;
  445. }
  446.  
  447. //----------------------------------------------------------------------------------------
  448. // CTextPart::SetFontSize
  449. //----------------------------------------------------------------------------------------
  450.  
  451. void CTextPart::SetFontSize(short fontSize)
  452. {
  453.     TOffsetRange range;
  454.     
  455.     long sizeFlag = 0;
  456.     TAttrObjModifier modifier(kSizeAttr, &fontSize, sizeFlag);
  457.         
  458.     fEditText->GetSelectionRange(&range);
  459.     fEditText->UpdateRangeRuns(&range, &modifier);
  460.         
  461.     InvalidateAllFrames(kContentFrameId, NULL, NULL);
  462. }
  463.  
  464. //----------------------------------------------------------------------------------------
  465. // CTextPart::SetFont
  466. //----------------------------------------------------------------------------------------
  467.  
  468. void CTextPart::SetFont(const Str255 fontName)
  469. {
  470.     TOffsetRange range;
  471.     short fontNumber;
  472.     long sizeFlag = 0;
  473.     
  474.     GetFNum(fontName, &fontNumber);
  475.     
  476.     TAttrObjModifier modifier(kFontAttr, &fontNumber);
  477.         
  478.     fEditText->GetSelectionRange(&range);
  479.     fEditText->UpdateRangeRuns(&range, &modifier);
  480.         
  481.     InvalidateAllFrames(kContentFrameId, NULL, NULL);
  482. }
  483.  
  484. //----------------------------------------------------------------------------------------
  485. // CTextPart::GetFontSize
  486. //----------------------------------------------------------------------------------------
  487.  
  488. Boolean CTextPart::GetFontSize(short& fontSize) const
  489. {
  490.     TOffsetRange selRange;
  491.     fEditText->GetSelectionRange(&selRange);
  492.     
  493.     const CRunObject* startRun = fEditText->Char2TextRun(selRange.Start());
  494.     const CRunObject* endRun = fEditText->Char2TextRun(selRange.End());
  495.     
  496.     if (startRun == endRun && startRun != NULL)
  497.     {
  498.         startRun->GetAttributeValue(kSizeAttr, &fontSize);
  499.         return true;
  500.     }
  501.     else
  502.         return false;
  503. }
  504.  
  505. //----------------------------------------------------------------------------------------
  506. // CTextPart::GetFont
  507. //----------------------------------------------------------------------------------------
  508.  
  509. Boolean CTextPart::GetFont(Str255 fontName) const
  510. {
  511.     TOffsetRange selRange;
  512.     fEditText->GetSelectionRange(&selRange);
  513.     
  514.     const CRunObject* startRun = fEditText->Char2TextRun(selRange.Start());
  515.     const CRunObject* endRun = fEditText->Char2TextRun(selRange.End());
  516.     
  517.     if (startRun == endRun && startRun != NULL)
  518.     {
  519.         short fontNumber;
  520.         startRun->GetAttributeValue(kFontAttr, &fontNumber);
  521.         ::GetFontName(fontNumber, fontName);
  522.         return true;
  523.     }
  524.     else
  525.         return false;
  526. }
  527.  
  528. //----------------------------------------------------------------------------------------
  529. // CTextPart::SetSelectionJustification
  530. //----------------------------------------------------------------------------------------
  531.  
  532. void CTextPart::SetSelectionJustification(CTextPart::Justification justify) const
  533. {
  534.     CTextPart* self = (CTextPart *) this;
  535.     
  536.     TOffsetRange range;    
  537.     fEditText->GetSelectionRange(&range);
  538.     
  539.     TAttrObjModifier modifier(kJustAttr, &justify /*, kApplyJust */);
  540.         
  541.     fEditText->UpdateRangeRulers(&range, &modifier);
  542.         
  543.     self->InvalidateAllFrames(kContentFrameId, NULL, NULL);
  544. }
  545.  
  546. //----------------------------------------------------------------------------------------
  547. // CTextPart::GetSelectionJustification
  548. //----------------------------------------------------------------------------------------
  549.  
  550. CTextPart::Justification CTextPart::GetSelectionJustification() const
  551. {
  552.     TOffsetRange selRange;
  553.     fEditText->GetSelectionRange(&selRange);
  554.     
  555.     const CRulerObject* currentRuler = fEditText->Offset2Ruler(selRange.rangeStart);
  556.     
  557.     Justification currJust;
  558.     currentRuler->GetAttributeValue(kJustAttr, &currJust);
  559.     
  560.     return currJust;
  561. }
  562.  
  563. //----------------------------------------------------------------------------------------
  564. // CTextPart::GetAnyFacet
  565. //----------------------------------------------------------------------------------------
  566.  
  567. CTextFacet* CTextPart::GetAnyFacet(XMPTypeToken presentation)
  568. {
  569.     FW_CFacet* facet = NULL;
  570.     FW_CPartFrameIterator iter1(this, presentation);
  571.     while (!iter1.IsDone())
  572.     {
  573.         FW_CFrameFacetIterator iter2(iter1.CurrentItem());
  574.         if (!iter2.IsDone())
  575.         {
  576.             facet = iter2.CurrentItem();
  577.             break;
  578.         }
  579.         iter1.Next();
  580.     }
  581.     return (CTextFacet *) facet;
  582. }
  583.  
  584. //----------------------------------------------------------------------------------------
  585. // CTextPart::HandleEmbedMenuEvent
  586. //----------------------------------------------------------------------------------------
  587.  
  588. void CTextPart::HandleEmbedMenuEvent(short item)
  589. {
  590.     XMPPart* embeddedPart;
  591.  
  592.     XMPStorageUnit* su = GetStorageUnit();
  593.     
  594.     switch (item)
  595.     {
  596.         case 1:
  597.             embeddedPart = su->GetDraft()->CreatePart("Apple:Kind:Framework:Sample:Textension", NULL);
  598.             break;
  599.         case 2:
  600.             embeddedPart = su->GetDraft()->CreatePart("Apple:Kind:Framework:Sample:QDraw", NULL);
  601.             break;
  602.         case 3:
  603.             embeddedPart = su->GetDraft()->CreatePart("Apple:Kind:Framework:Sample:Clock", NULL);
  604.             break;
  605.         case 4:
  606.             embeddedPart = su->GetDraft()->CreatePart("Apple:OSType:Scrap:moov", NULL);
  607.             break;
  608.         default:
  609.             break;
  610.     }
  611.     
  612.     // ----- Default frame shape -----
  613.     
  614.     FW_CRect frameRect(ff(0), ff(0), ff(80), ff(80));
  615.     
  616.     this->HandleEmbedPart(embeddedPart, frameRect);
  617.     
  618.     // ----- Release Part -----
  619.     embeddedPart->Release();
  620.     
  621. }
  622.  
  623. //----------------------------------------------------------------------------------------
  624. // CTextPart::HandleEmbedPart
  625. //----------------------------------------------------------------------------------------
  626.  
  627. void CTextPart::HandleEmbedPart(XMPPart* xmpPart, const FW_CRect& frameRect)
  628. {
  629.     XMPShape *frameShape = ::NewXMPShape(frameRect);
  630.  
  631.     // ----- Create a textension run object
  632.     
  633.     CEmbeddedRun* runObject = new CEmbeddedRun();
  634.     runObject->InitEmbeddedRun();
  635.     
  636.     short selectionWidth = runObject->GetSelectionWidth();
  637.  
  638.     // ----- Get the current selection as the embedding position.
  639.     
  640.     TOffsetRange range;
  641.     fEditText->GetSelectionRange(&range);
  642.     FW_SPlatformPoint position = fEditText->Char2Point(range.Start());
  643.     // ----- Account Textension border
  644.     position.v += selectionWidth, position.h +=selectionWidth;
  645.         
  646.     XMPTransform* externalXForm = ::NewXMPTransform(position);
  647.     
  648.     // ----- Create the proxyPart -----
  649.     CTextProxyRun* proxyRun = (CTextProxyRun *) NewProxyRun();
  650.     FW_SPlatformRect qdFrameRect = frameRect;
  651.     ::OffsetRect(&qdFrameRect, selectionWidth, selectionWidth);
  652.     proxyRun->SetBoundingBox(qdFrameRect);
  653.         
  654.     // ----- Embed the part -----
  655.     EmbedPart(xmpPart, proxyRun, fMainPresentation,
  656.               GetSession()->Tokenize(kXMPViewAsFrame), kNoPresentation,
  657.               externalXForm, frameShape, TRUE);
  658.  
  659.     // ----- ReplaceRange draws so we'd better be focused.
  660.     
  661.     CTextDrawInitiator di(GetAnyFacet(fMainPresentation));
  662.     
  663.     runObject->SetProxyRun(proxyRun);
  664.  
  665.     // Replace the current selection with the textension run object
  666.     
  667.     TReplaceParams replaceParams(runObject);
  668.     fEditText->ReplaceRange(range.Start(), range.End(), &replaceParams);
  669. }
  670.  
  671. //----------------------------------------------------------------------------------------
  672. // CTextPart::InitializeTextension
  673. //----------------------------------------------------------------------------------------
  674.  
  675. void CTextPart::InitializeTextension()
  676. {
  677.     static Boolean initialized = false;
  678.     
  679.     if (!initialized)
  680.     {
  681.         initialized = true;
  682.         
  683.         SetFractEnable(true);
  684.         
  685.         CTextension::TextensionStart();
  686.         
  687.         CQDTextRun* textRun = new CQDTextRun;
  688.         textRun->IQDTextRun();
  689.         
  690.         CTextension::RegisterIORun(textRun);
  691.         
  692.         CEmbeddedRun *embeddedRun = new CEmbeddedRun;
  693.         embeddedRun->InitEmbeddedRun();
  694.         
  695.         CTextension::RegisterIORun(embeddedRun);
  696.         
  697.         CBasicRuler* rulerObj = new CBasicRuler;
  698.         rulerObj->IBasicRuler();
  699.         
  700.         CTextension::RegisterIORuler(rulerObj);
  701.     }
  702. }
  703.  
  704. //----------------------------------------------------------------------------------------
  705. // CTextPart::CreateEditText
  706. //----------------------------------------------------------------------------------------
  707.  
  708. void CTextPart::CreateEditText()
  709. {
  710.     CTextPart::InitializeTextension();
  711.  
  712.     TTextensionHandlers textensionHandlers;
  713.     
  714.     fEditText = new COpenDocText;
  715.     fEditText->InitOpenDocText(NULL, &textensionHandlers, kLargeSize);
  716. }
  717.  
  718. //----------------------------------------------------------------------------------------
  719. // CTextPart::StuffInTheText
  720. //----------------------------------------------------------------------------------------
  721.  
  722. void CTextPart::StuffInTheText(FW_PlatformHandle text, Size textSize)
  723. {
  724. FW_UNUSED(text);
  725. FW_UNUSED(textSize);
  726. #if 0
  727.     // TEInsert draws, but we're not ready to draw at the time the part is internalized,
  728.     // because parts don't have grafports. So here we create a temporary port to draw
  729.     // in and set the clip region to empty.
  730.     
  731.     GrafPtr savePort = (*fEditText)->inPort;
  732.     GrafPort port;
  733.     OpenPort(&port);
  734.     SetRectRgn(port.clipRgn, 0, 0, 0, 0); 
  735.     (*fEditText)->inPort = &port;
  736.     
  737.     TEInsert((Ptr) *text, textSize, fEditText);
  738.     
  739.     ClosePort(&port);
  740.     (*fEditText)->inPort = savePort;
  741. #endif
  742. }
  743.  
  744. //----------------------------------------------------------------------------------------
  745. // CTextPart::StuffInTheStyles
  746. //----------------------------------------------------------------------------------------
  747.  
  748. void CTextPart::StuffInTheStyles(FW_PlatformHandle styles, Size stylesSize)
  749. {
  750. FW_UNUSED(styles);
  751. FW_UNUSED(stylesSize);
  752. #if 0
  753.  
  754.     SetStylScrap(0, 32767, (StScrpHandle) styles, false, fEditText);
  755. #endif
  756. }
  757.  
  758.